$import("com.joypard.platform.security.role.roleresources.RoleResourcesView");
$import("com.joypard.platform.security.role.roleresources.RoleResourcesService");

/**
 * 角色管理-控制器
 */
K.defCtrl("com.joypard.platform.security.role.roleresources.RoleResourcesCtrl", {

	// 初始化
	initialize : function() {
		this.view = RoleResourcesView.instance();
		this.service = RoleResourcesService.instance();
		E.addListener("getRsByRoleIdEvent", this.onGetRsByRoleIdEvent, this);
		E.addListener("assignResourcesEvent", this.onAssignResourcesEvent, this);
	},

	/**
	 * 根据角色id查询资源事件
	 */
	onGetRsByRoleIdEvent : function(params) {
		var me = this;
		var input = K.input({
			params : params,
			success : function(text) {
				var output = K.createOutput(text);
				E.fireEvent("getRsByRoleIdSuccessEvent", output);
			}
		});
		this.service.getRsByRoleId(input);
	},

	/**
	 * 为角色分配资源
	 */
	onAssignResourcesEvent : function(params) {
		var me = this;
		var input = K.input({
			params : params,
			success : function() {
				E.fireEvent("assignResourcesSuccessEvent");
			}
		});
		this.service.assignResources(input);
	}

})